package com.example.controller;

import com.example.entity.po.Notification;
import com.example.entity.vo.TeachingVo;
import com.example.utils.ResultUtils;
import com.example.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RestController
public class NotificationController {
    @Autowired
    private NotificationService notificationService;

    @GetMapping("/notification")
    @ResponseBody
    public ResultUtils notificationList(){
        List<Notification> notifications= notificationService.queryNotification();
        if (notifications.size()==0){
            return ResultUtils.Failure("获取通知失败或无通知",null);
        }else {
            return ResultUtils.Successful("获取通知成功",notifications);
        }
    }

    @PostMapping("/addNotification")
    @ResponseBody
    public ResultUtils addNotification(@RequestBody Notification notification){
        int res= notificationService.addNotification(notification);
        if (res==0){
            return ResultUtils.Failure("添加通知失败",null);
        }else {
            return ResultUtils.Successful("添加通知成功",null);
        }
    }

    @PostMapping("/deleteNotification")
    @ResponseBody
    public ResultUtils deleteNotification(int id){
        int res= notificationService.deleteNotification(id);
        if (res==0){
            return ResultUtils.Failure("删除通知失败",null);
        }else {
            return ResultUtils.Successful("删除通知成功",null);
        }
    }

    @PostMapping("/fuzzyNotification")
    public ResultUtils fuzzyNotification(String noticeTitle){
        List<Notification> notices= notificationService.fuzzyNotification(noticeTitle);
        if (notices.size()==0){
            return ResultUtils.Failure("搜索通知失败或无该通知",null);
        }else {
            return ResultUtils.Successful("搜索通知成功",notices);
        }
    }

}
